home *** CD-ROM | disk | FTP | other *** search
- //*************************************
- //*** Print.cmm - Print a text file ***
- //*** ver.1 ***
- //*************************************
-
- #define DEFAULT_PRINTER_SPEC "PRN"
-
- main(argc,argv)
- {
- if ( argc == 2 ) {
- PrinterSpec = DEFAULT_PRINTER_SPEC;
- FileSpec = argv[1];
- } else if ( argc == 3 ) {
- PrinterSpec = argv[1];
- FileSpec = argv[2];
- } else {
- Instructions();
- }
-
- // Open file to print
- if ( !(fpIn = fopen(FileSpec,"rt")) ) {
- printf("\aUnable to open \"%s\" for reading.\n\n",
- FileSpec);
- Instructions();
- }
- // Open printer to write to
- if ( !(fpOut = fopen(PrinterSpec,"wt")) ) {
- fclose(fpIn);
- printf("\aUnable to open printer spec \"%s\" for output.\n\n",
- PrinterSpec);
- Instructions();
- }
-
- // read each input line and write to output
- while ( line = fgets(fpIn) ) {
- if ( EOF == fputs(line,fpOut) ) {
- fclose(fpOut); fclose(fpIn);
- printf("\aError writing to output printer \"%s\"\n\n",
- PrinterSpec);
- Instructions();
- }
- }
-
- // close files; all done
- fclose(fpOut);
- fclose(fpIn);
- return EXIT_SUCCESS;
- }
-
- Instructions()
- {
- puts("\a");
- puts(`Print.cmm - Print a text file to specified printer`)
- puts(``)
- puts(`USAGE: CEnvi Print.cmm [Printer] <FileSpec>`)
- puts(``)
- puts(`WHERE: Printer: Optional name of printer device; default is `
- DEFAULT_PRINTER_SPEC)
- puts(` FileSpec: Specification of file to print`)
- puts(``)
- puts(`EXAMPLES: CEnvi Print C:\AutoExec.bat`)
- puts(` CEnvi Print LPT2 G:\MYTEXT.DOC`)
- puts(``)
- if ( defined(_WINDOWS_) ) {
- puts(`Press any key to exit...`)
- getch()
- }
- exit(EXIT_FAILURE);
- }
-